<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  function ajax(url, callback) {
    //1.创建XMLHttpRequest对象
    var xmlhttp

    if (window.XMLHttpRequest) {
      xmlhttp = new XMLHttpRequest()
    } else {
      // 兼容早起浏览器
      xmlhttp = new ActiveXObject('Microsoft.XMLHTTP')
    }
    //2. 发送请求
    xmlhttp.open('GET', url, true)
    xmlhttp.send()
    //3.接受服务端数据
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        var obj = JSON.parse(xmlhttp.responseText)
        // console.log(obj)
        callback(obj)
      }
    }
  }
  ajax('https://api.apiopen.top/getJoke', res => console.log(res));

</script>

</html>